



<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#FFF">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon.png">

<link rel="icon" type="image/ico" sizes="32x32" href="/blog/images/favicon.ico">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">


<link rel="alternate" type="application/rss+xml" title="凡尘一叶" href="http://fyduyu.gitee.io/blog/rss.xml" />
<link rel="alternate" type="application/atom+xml" title="凡尘一叶" href="http://fyduyu.gitee.io/blog/atom.xml" />
<link rel="alternate" type="application/json" title="凡尘一叶" href="http://fyduyu.gitee.io/blog/feed.json" />

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Mulish:300,300italic,400,400italic,700,700italic%7CFredericka%20the%20Great:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20JP:300,300italic,400,400italic,700,700italic%7CNoto%20Serif%20SC:300,300italic,400,400italic,700,700italic%7CInconsolata:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/blog/css/app.css?v=0.2.5">

  
  <meta name="keywords" content="分布式" />


<link rel="canonical" href="http://fyduyu.gitee.io/blog/2020/12/24/Spring%20Cloud%20Stream/">



  <title>
Spring Cloud Stream - SpringCloud |
blog = 凡尘一叶</title>
<meta name="generator" content="Hexo 5.3.0"></head>
<body itemscope itemtype="http://schema.org/WebPage">
  <div id="loading">
    <div class="cat">
      <div class="body"></div>
      <div class="head">
        <div class="face"></div>
      </div>
      <div class="foot">
        <div class="tummy-end"></div>
        <div class="bottom"></div>
        <div class="legs left"></div>
        <div class="legs right"></div>
      </div>
      <div class="paw">
        <div class="hands left"></div>
        <div class="hands right"></div>
      </div>
    </div>
  </div>
  <div id="container">
    <header id="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="inner">
        <div id="brand">
          <div class="pjax">
          
  <h1 itemprop="name headline">Spring Cloud Stream
  </h1>
  
<div class="meta">
  <span class="item" title="创建时间：2020-12-24 22:00:53">
    <span class="icon">
      <i class="ic i-calendar"></i>
    </span>
    <span class="text">发表于</span>
    <time itemprop="dateCreated datePublished" datetime="2020-12-24T22:00:53+08:00">2020-12-24</time>
  </span>
  <span class="item" title="本文字数">
    <span class="icon">
      <i class="ic i-pen"></i>
    </span>
    <span class="text">本文字数</span>
    <span>7.6k</span>
    <span class="text">字</span>
  </span>
  <span class="item" title="阅读时长">
    <span class="icon">
      <i class="ic i-clock"></i>
    </span>
    <span class="text">阅读时长</span>
    <span>7 分钟</span>
  </span>
</div>


          </div>
        </div>
        <nav id="nav">
  <div class="inner">
    <div class="toggle">
      <div class="lines" aria-label="切换导航栏">
        <span class="line"></span>
        <span class="line"></span>
        <span class="line"></span>
      </div>
    </div>
    <ul class="menu">
      <li class="item title"><a href="/blog/" rel="start">blog</a></li>
    </ul>
    <ul class="right">
      <li class="item theme">
        <i class="ic i-sun"></i>
      </li>
      <li class="item search">
        <i class="ic i-search"></i>
      </li>
    </ul>
  </div>
</nav>

      </div>
      <div id="imgs" class="pjax">
        <ul>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1gicivghyooj20zk0m8dir.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1gipesx5fdwj20zk0m81kx.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giclfb3vzhj20zk0m8wny.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giclffsa1cj20zk0m811l.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1gipevarprfj20zk0m8npd.jpg"></li>
          <li class="item" data-background-image="https://tva4.sinaimg.cn/large/6833939bly1giciusoyjnj219g0u0x56.jpg"></li>
        </ul>
      </div>
    </header>
    <div id="waves">
      <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
        <defs>
          <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
        </defs>
        <g class="parallax">
          <use xlink:href="#gentle-wave" x="48" y="0" />
          <use xlink:href="#gentle-wave" x="48" y="3" />
          <use xlink:href="#gentle-wave" x="48" y="5" />
          <use xlink:href="#gentle-wave" x="48" y="7" />
        </g>
      </svg>
    </div>
    <main>
      <div class="inner">
        <div id="main" class="pjax">
          
  <div class="article wrap">
    
<div class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
<i class="ic i-home"></i>
<span><a href="/blog/">首页</a></span><i class="ic i-angle-right"></i>
<span  class="current" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"><a href="/blog/categories/SpringCloud/" itemprop="item" rel="index" title="分类于 SpringCloud"><span itemprop="name">SpringCloud</span></a>
<meta itemprop="position" content="1" /></span>
</div>

    <article itemscope itemtype="http://schema.org/Article" class="post block" lang="zh-CN">
  <link itemprop="mainEntityOfPage" href="http://fyduyu.gitee.io/blog/2020/12/24/Spring%20Cloud%20Stream/">

  <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="image" content="/blog/images/touxiang.jpg">
    <meta itemprop="name" content="杜朝宇">
    <meta itemprop="description" content=", 个人博客&编程笔记">
  </span>

  <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="凡尘一叶">
  </span>

  <div class="body md" itemprop="articleBody">
    

    <p>现在一个很项目可能分为三部分:<br>
 前端 —&gt; 后端 ----&gt; 大数据<br>
而后端开发使用消息中间件，可能会使用 RabbitMq<br>
 而大数据开发，一般都是使用 Kafka,<br>
 那么一个项目中有多个消息中间件，对于程序员，因为人员都不友好</p>
<p>而 Spring Cloud Stream 就类似 jpa, 屏蔽底层消息中间件的差异，程序员主要操作 Spring Cloud Stream 即可</p>
<p>不需要管底层是 kafka 还是 rabbitMq</p>
<h1 id="消息中间的几大应用场景"><a class="markdownIt-Anchor" href="#消息中间的几大应用场景">#</a> 消息中间的几大应用场景</h1>
<p>1、异步处理</p>
<p>比如用户在电商网站下单，下单完成后会给用户推送短信或邮件，发短信和邮件的过程就可以异步完成。因为下单付款是核心业务，发邮件和短信并不属于核心功能，并且可能耗时较长，所以针对这种业务场景可以选择先放到消息队列中，有其他服务来异步处理。</p>
<p>2、应用解耦：</p>
<p>假设公司有几个不同的系统，各系统在某些业务有联动关系，比如 A 系统完成了某些操作，需要触发 B 系统及 C 系统。如果 A 系统完成操作，主动调用 B 系统的接口或 C 系统的接口，可以完成功能，但是各个系统之间就产生了耦合。用消息中间件就可以完成解耦，当 A 系统完成操作将数据放进消息队列，B 和 C 系统去订阅消息就可以了。这样各系统只要约定好消息的格式就好了。</p>
<p>3、流量削峰</p>
<p>比如秒杀活动，一下子进来好多请求，有的服务可能承受不住瞬时高并发而崩溃，所以针对这种瞬时高并发的场景，在中间加一层消息队列，把请求先入队列，然后再把队列中的请求平滑的推送给服务，或者让服务去队列拉取。</p>
<p>4、日志处理</p>
<p>kafka 最开始就是专门为了处理日志产生的。</p>
<p>当碰到上面的几种情况的时候，就要考虑用消息队列了。如果你碰巧使用的是 RabbitMQ 或者 kafka ，而且同样也是在使用 Spring Cloud ，那可以考虑下用 Spring Cloud Stream。</p>
<h1 id="使用-spring-cloud-stream-rabbitmq"><a class="markdownIt-Anchor" href="#使用-spring-cloud-stream-rabbitmq">#</a> 使用 Spring Cloud Stream &amp;&amp; RabbitMQ</h1>
<p>介绍下面的例子之前，假定你已经对 RabbitMQ 有一定的了解。</p>
<p>首先来认识一下 Spring Cloud Stream 中的几个重要概念。</p>
<p><em>Destination Binders</em>：目标绑定器，目标指的是 kafka 还是 RabbitMQ，绑定器就是封装了目标中间件的包。如果操作的是 kafka 就使用 kafka binder ，如果操作的是 RabbitMQ 就使用 rabbitmq binder。</p>
<p><em>Destination Bindings</em>：外部消息传递系统和应用程序之间的桥梁，提供消息的 “生产者” 和 “消费者”（由目标绑定器创建）</p>
<p><em>Message</em>：一种规范化的数据结构，生产者和消费者基于这个数据结构通过外部消息系统与目标绑定器和其他应用程序通信。</p>
<h2 id="创建生产者"><a class="markdownIt-Anchor" href="#创建生产者">#</a> 创建生产者</h2>
<h3 id="pom"><a class="markdownIt-Anchor" href="#pom">#</a> pom</h3>
<figure class="highlight xml"><figcaption data-lang="XML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">&lt;!--stream rabbit --></span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="3"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="4"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-cloud-starter-stream-rabbit<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr></table></figure><figure class="highlight xml"><figcaption data-lang="XML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="2"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="3"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="4"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-web<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="5"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="6"></td><td><pre>        <span class="token comment">&lt;!-- 监控 --></span></pre></td></tr><tr><td data-num="7"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="8"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="9"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-actuator<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="10"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="11"></td><td><pre>        <span class="token comment">&lt;!--eureka client--></span></pre></td></tr><tr><td data-num="12"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="13"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="14"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-cloud-starter-netflix-eureka-client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="15"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="16"></td><td><pre>        <span class="token comment">&lt;!--stream rabbit --></span></pre></td></tr><tr><td data-num="17"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="18"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="19"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-cloud-starter-stream-rabbit<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="20"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="21"></td><td><pre>        <span class="token comment">&lt;!-- 热部署 --></span></pre></td></tr><tr><td data-num="22"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="23"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="24"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-devtools<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="25"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>runtime<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="26"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>optional</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>optional</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="27"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="28"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="29"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.projectlombok<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="30"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>lombok<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="31"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>optional</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>optional</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="32"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="33"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="34"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="35"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="36"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="37"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="38"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">></span></span></pre></td></tr></table></figure><h3 id="配置文件"><a class="markdownIt-Anchor" href="#配置文件">#</a> 配置文件</h3>
<p>重要的</p>
<figure class="highlight yaml"><figcaption data-lang="YAML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token key atrule">bindings</span><span class="token punctuation">:</span> <span class="token comment">#服务的整合处理</span></pre></td></tr><tr><td data-num="2"></td><td><pre>  <span class="token key atrule">output</span><span class="token punctuation">:</span>  <span class="token comment">#这个名字是一个通道的名称</span></pre></td></tr><tr><td data-num="3"></td><td><pre>    <span class="token key atrule">destination</span><span class="token punctuation">:</span> studyExchange  <span class="token comment">#表示要使用的 Exchange 名称定义</span></pre></td></tr><tr><td data-num="4"></td><td><pre>    <span class="token key atrule">content-type</span><span class="token punctuation">:</span> application/json  <span class="token comment">#设置消息类型</span></pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token key atrule">binder</span><span class="token punctuation">:</span> defaultRabbit <span class="token comment">#设置要绑定的消息服务的具体设置</span></pre></td></tr></table></figure><figure class="highlight yaml"><figcaption data-lang="YAML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token key atrule">server</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="2"></td><td><pre>  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">8801</span></pre></td></tr><tr><td data-num="3"></td><td><pre></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token key atrule">spring</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="5"></td><td><pre>  <span class="token key atrule">application</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="6"></td><td><pre>    <span class="token key atrule">name</span><span class="token punctuation">:</span> stream<span class="token punctuation">-</span>rabbit<span class="token punctuation">-</span>customer<span class="token punctuation">-</span>group1</pre></td></tr><tr><td data-num="7"></td><td><pre>  <span class="token key atrule">cloud</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="8"></td><td><pre>    <span class="token key atrule">stream</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="9"></td><td><pre>      <span class="token key atrule">binders</span><span class="token punctuation">:</span>  <span class="token comment">#要绑定的 rabbitmq 的服务信息</span></pre></td></tr><tr><td data-num="10"></td><td><pre>        <span class="token key atrule">defaultRabbit</span><span class="token punctuation">:</span>  <span class="token comment">#要定义的名称，用于 binding 整合</span></pre></td></tr><tr><td data-num="11"></td><td><pre>          <span class="token key atrule">type</span><span class="token punctuation">:</span> rabbit  <span class="token comment">#消息组件类型</span></pre></td></tr><tr><td data-num="12"></td><td><pre>          <span class="token key atrule">environment</span><span class="token punctuation">:</span>  <span class="token comment">#设置 rabbitmq 的相关环境</span></pre></td></tr><tr><td data-num="13"></td><td><pre>            <span class="token key atrule">spring</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="14"></td><td><pre>              <span class="token key atrule">rabbitmq</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="15"></td><td><pre>                <span class="token key atrule">host</span><span class="token punctuation">:</span> localhost</pre></td></tr><tr><td data-num="16"></td><td><pre>                <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">5672</span></pre></td></tr><tr><td data-num="17"></td><td><pre>                <span class="token key atrule">username</span><span class="token punctuation">:</span> guest</pre></td></tr><tr><td data-num="18"></td><td><pre>                <span class="token key atrule">password</span><span class="token punctuation">:</span> guest</pre></td></tr><tr><td data-num="19"></td><td><pre>      <span class="token key atrule">bindings</span><span class="token punctuation">:</span> <span class="token comment">#服务的整合处理</span></pre></td></tr><tr><td data-num="20"></td><td><pre>        <span class="token key atrule">output</span><span class="token punctuation">:</span>  <span class="token comment">#这个名字是一个通道的名称</span></pre></td></tr><tr><td data-num="21"></td><td><pre>          <span class="token key atrule">destination</span><span class="token punctuation">:</span> studyExchange  <span class="token comment">#表示要使用的 Exchange 名称定义</span></pre></td></tr><tr><td data-num="22"></td><td><pre>          <span class="token key atrule">content-type</span><span class="token punctuation">:</span> application/json  <span class="token comment">#设置消息类型</span></pre></td></tr><tr><td data-num="23"></td><td><pre>          <span class="token key atrule">binder</span><span class="token punctuation">:</span> defaultRabbit <span class="token comment">#设置要绑定的消息服务的具体设置</span></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token key atrule">eureka</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="25"></td><td><pre>  <span class="token key atrule">client</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="26"></td><td><pre>    <span class="token key atrule">service-url</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="27"></td><td><pre>      <span class="token key atrule">defaultZone</span><span class="token punctuation">:</span> http<span class="token punctuation">:</span>//localhost<span class="token punctuation">:</span>7001/eureka</pre></td></tr><tr><td data-num="28"></td><td><pre>  <span class="token key atrule">instance</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="29"></td><td><pre>    <span class="token key atrule">lease-renewal-interval-in-seconds</span><span class="token punctuation">:</span> <span class="token number">2</span> <span class="token comment">#设置心跳间隔时间 （默认 30）</span></pre></td></tr><tr><td data-num="30"></td><td><pre>    <span class="token key atrule">lease-expiration-duration-in-seconds</span><span class="token punctuation">:</span> <span class="token number">5</span>   <span class="token comment"># 如果现在超过了 5 秒的间隔时间 (默认是 90s)</span></pre></td></tr><tr><td data-num="31"></td><td><pre>    <span class="token key atrule">instance-id</span><span class="token punctuation">:</span> send<span class="token punctuation">-</span>8801.com  <span class="token comment">#在信息列表访问时显示的主机名字</span></pre></td></tr><tr><td data-num="32"></td><td><pre>    <span class="token key atrule">prefer-ip-address</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>     <span class="token comment">#访问的路径变为 ip 地址</span></pre></td></tr></table></figure><h3 id="service和实现类"><a class="markdownIt-Anchor" href="#service和实现类">#</a> service 和实现类</h3>
<p>service 定义发送消息</p>
<p>Source 注意不要导错</p>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">//Source 注意不要导错</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token comment">//org.springframework.cloud.stream.messaging.Source</span></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token annotation punctuation">@EnableBinding</span><span class="token punctuation">(</span><span class="token class-name">Source</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>    <span class="token comment">// 定义消息的推送管道 </span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">IMessageProviderIml</span> <span class="token keyword">implements</span> <span class="token class-name">IMessageProvider</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token annotation punctuation">@Resource</span></pre></td></tr><tr><td data-num="6"></td><td><pre>    <span class="token keyword">private</span> <span class="token class-name">MessageChannel</span> output<span class="token punctuation">;</span><span class="token comment">// 消息发送管道</span></pre></td></tr><tr><td data-num="7"></td><td><pre></pre></td></tr><tr><td data-num="8"></td><td><pre>    <span class="token annotation punctuation">@Override</span></pre></td></tr><tr><td data-num="9"></td><td><pre>    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="10"></td><td><pre>        <span class="token class-name">String</span> serial <span class="token operator">=</span> UUID<span class="token punctuation">.</span><span class="token function">randomUUID</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// 要发送的消息</span></pre></td></tr><tr><td data-num="11"></td><td><pre>        output<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span><span class="token class-name">MessageBuilder</span><span class="token punctuation">.</span><span class="token function">withPayload</span><span class="token punctuation">(</span>serial<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="12"></td><td><pre>        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"******serial:  "</span><span class="token operator">+</span>serial<span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="13"></td><td><pre>        <span class="token keyword">return</span> serial<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="14"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="15"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h3 id="controller"><a class="markdownIt-Anchor" href="#controller">#</a> controller</h3>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token annotation punctuation">@RestController</span></pre></td></tr><tr><td data-num="2"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">SendMessageController</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="3"></td><td><pre></pre></td></tr><tr><td data-num="4"></td><td><pre>    <span class="token annotation punctuation">@Resource</span></pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token keyword">private</span> <span class="token class-name">IMessageProvider</span> messageProvider<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre>    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">"/sendMessage"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="8"></td><td><pre>    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">sendMessage</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="9"></td><td><pre>        <span class="token keyword">return</span> messageProvider<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="10"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h3 id="可以测试"><a class="markdownIt-Anchor" href="#可以测试">#</a> 可以测试</h3>
<p>启动 rabbitmq</p>
<p>启动 7001,8801</p>
<p>​		确定 8801 后，会在 rabbitmq 中创建一个 Exchange, 就是我们配置文件中配置的 exchange</p>
<p>访问 8801 的 /sendMessage</p>
<h2 id="创建消费者"><a class="markdownIt-Anchor" href="#创建消费者">#</a> 创建消费者</h2>
<h3 id="pom文件"><a class="markdownIt-Anchor" href="#pom文件">#</a> pom 文件</h3>
<p>主要的</p>
<figure class="highlight xml"><figcaption data-lang="XML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token comment">&lt;!--stream rabbit --></span></pre></td></tr><tr><td data-num="2"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="3"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="4"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-cloud-starter-stream-rabbit<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="5"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr></table></figure><figure class="highlight xml"><figcaption data-lang="XML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="2"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="3"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="4"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-web<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="5"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="6"></td><td><pre>        <span class="token comment">&lt;!-- 监控 --></span></pre></td></tr><tr><td data-num="7"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="8"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="9"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-actuator<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="10"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="11"></td><td><pre>        <span class="token comment">&lt;!--eureka client--></span></pre></td></tr><tr><td data-num="12"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="13"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="14"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-cloud-starter-netflix-eureka-client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="15"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="16"></td><td><pre>        <span class="token comment">&lt;!--stream rabbit --></span></pre></td></tr><tr><td data-num="17"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="18"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.cloud<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="19"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-cloud-starter-stream-rabbit<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="20"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="21"></td><td><pre>        <span class="token comment">&lt;!-- 热部署 --></span></pre></td></tr><tr><td data-num="22"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="23"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="24"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-devtools<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="25"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>runtime<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="26"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>optional</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>optional</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="27"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="28"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="29"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.projectlombok<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="30"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>lombok<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="31"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>optional</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>optional</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="32"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="33"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="34"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">></span></span>org.springframework.boot<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="35"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">></span></span>spring-boot-starter-test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="36"></td><td><pre>            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>scope</span><span class="token punctuation">></span></span>test<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>scope</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="37"></td><td><pre>        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">></span></span></pre></td></tr><tr><td data-num="38"></td><td><pre>    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">></span></span></pre></td></tr></table></figure><h3 id="配置文件-2"><a class="markdownIt-Anchor" href="#配置文件-2">#</a> 配置文件</h3>
<p>主要的</p>
<figure class="highlight yaml"><figcaption data-lang="YAML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token key atrule">bindings</span><span class="token punctuation">:</span> <span class="token comment">#服务的整合处理</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    <span class="token key atrule">input</span><span class="token punctuation">:</span>  <span class="token comment">#这个名字是一个通道的名称</span></pre></td></tr><tr><td data-num="3"></td><td><pre>      <span class="token key atrule">destination</span><span class="token punctuation">:</span> studyExchange  <span class="token comment">#表示要使用的 Exchange 名称定义 指定使用那个 Exchange</span></pre></td></tr><tr><td data-num="4"></td><td><pre>      <span class="token key atrule">content-type</span><span class="token punctuation">:</span> application/json  <span class="token comment">#设置消息类型</span></pre></td></tr><tr><td data-num="5"></td><td><pre>      <span class="token key atrule">binder</span><span class="token punctuation">:</span> defaultRabbit <span class="token comment">#设置要绑定的消息服务的具体设置</span></pre></td></tr></table></figure><figure class="highlight yaml"><figcaption data-lang="YAML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token key atrule">server</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="2"></td><td><pre>  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">8802</span></pre></td></tr><tr><td data-num="3"></td><td><pre></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token key atrule">spring</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="5"></td><td><pre>  <span class="token key atrule">application</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="6"></td><td><pre>    <span class="token key atrule">name</span><span class="token punctuation">:</span> cloud<span class="token punctuation">-</span>stream<span class="token punctuation">-</span>consumer</pre></td></tr><tr><td data-num="7"></td><td><pre>  <span class="token key atrule">cloud</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="8"></td><td><pre>    <span class="token key atrule">stream</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="9"></td><td><pre>      <span class="token key atrule">binders</span><span class="token punctuation">:</span>  <span class="token comment">#要绑定的 rabbitmq 的服务信息</span></pre></td></tr><tr><td data-num="10"></td><td><pre>        <span class="token key atrule">defaultRabbit</span><span class="token punctuation">:</span>  <span class="token comment">#要定义的名称，用于 binding 整合</span></pre></td></tr><tr><td data-num="11"></td><td><pre>          <span class="token key atrule">type</span><span class="token punctuation">:</span> rabbit  <span class="token comment">#消息组件类型</span></pre></td></tr><tr><td data-num="12"></td><td><pre>          <span class="token key atrule">environment</span><span class="token punctuation">:</span>  <span class="token comment">#设置 rabbitmq 的相关环境</span></pre></td></tr><tr><td data-num="13"></td><td><pre>            <span class="token key atrule">spring</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="14"></td><td><pre>              <span class="token key atrule">rabbitmq</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="15"></td><td><pre>                <span class="token key atrule">host</span><span class="token punctuation">:</span> localhost</pre></td></tr><tr><td data-num="16"></td><td><pre>                <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">5672</span></pre></td></tr><tr><td data-num="17"></td><td><pre>                <span class="token key atrule">username</span><span class="token punctuation">:</span> guest</pre></td></tr><tr><td data-num="18"></td><td><pre>                <span class="token key atrule">password</span><span class="token punctuation">:</span> guest</pre></td></tr><tr><td data-num="19"></td><td><pre>      <span class="token key atrule">bindings</span><span class="token punctuation">:</span> <span class="token comment">#服务的整合处理</span></pre></td></tr><tr><td data-num="20"></td><td><pre>        <span class="token key atrule">input</span><span class="token punctuation">:</span>  <span class="token comment">#这个名字是一个通道的名称</span></pre></td></tr><tr><td data-num="21"></td><td><pre>          <span class="token key atrule">destination</span><span class="token punctuation">:</span> studyExchange  <span class="token comment">#表示要使用的 Exchange 名称定义 指定使用那个 Exchange</span></pre></td></tr><tr><td data-num="22"></td><td><pre>          <span class="token key atrule">content-type</span><span class="token punctuation">:</span> application/json  <span class="token comment">#设置消息类型</span></pre></td></tr><tr><td data-num="23"></td><td><pre>          <span class="token key atrule">binder</span><span class="token punctuation">:</span> defaultRabbit <span class="token comment">#设置要绑定的消息服务的具体设置</span></pre></td></tr><tr><td data-num="24"></td><td><pre><span class="token key atrule">eureka</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="25"></td><td><pre>  <span class="token key atrule">client</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="26"></td><td><pre>    <span class="token key atrule">service-url</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="27"></td><td><pre>      <span class="token key atrule">defaultZone</span><span class="token punctuation">:</span> http<span class="token punctuation">:</span>//localhost<span class="token punctuation">:</span>7001/eureka</pre></td></tr><tr><td data-num="28"></td><td><pre>  <span class="token key atrule">instance</span><span class="token punctuation">:</span></pre></td></tr><tr><td data-num="29"></td><td><pre>    <span class="token key atrule">lease-renewal-interval-in-seconds</span><span class="token punctuation">:</span> <span class="token number">2</span> <span class="token comment">#设置心跳间隔时间 （默认 30）</span></pre></td></tr><tr><td data-num="30"></td><td><pre>    <span class="token key atrule">lease-expiration-duration-in-seconds</span><span class="token punctuation">:</span> <span class="token number">5</span>   <span class="token comment"># 如果现在超过了 5 秒的间隔时间 (默认是 90s)</span></pre></td></tr><tr><td data-num="31"></td><td><pre>    <span class="token key atrule">instance-id</span><span class="token punctuation">:</span> receive<span class="token punctuation">-</span>8802.com  <span class="token comment">#在信息列表访问时显示的主机名字</span></pre></td></tr><tr><td data-num="32"></td><td><pre>    <span class="token key atrule">prefer-ip-address</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>     <span class="token comment">#访问的路径变为 ip 地址</span></pre></td></tr></table></figure><h3 id="业务类消费数据"><a class="markdownIt-Anchor" href="#业务类消费数据">#</a> 业务类 (消费数据)</h3>
<figure class="highlight java"><figcaption data-lang="java"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token keyword">package</span> <span class="token namespace">com<span class="token punctuation">.</span>duyu<span class="token punctuation">.</span>springcloud<span class="token punctuation">.</span>controller</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="2"></td><td><pre></pre></td></tr><tr><td data-num="3"></td><td><pre><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>factory<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">Value</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="4"></td><td><pre><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>cloud<span class="token punctuation">.</span>stream<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">EnableBinding</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="5"></td><td><pre><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>cloud<span class="token punctuation">.</span>stream<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span></span><span class="token class-name">StreamListener</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="6"></td><td><pre><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>cloud<span class="token punctuation">.</span>stream<span class="token punctuation">.</span>messaging<span class="token punctuation">.</span></span><span class="token class-name">Sink</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="7"></td><td><pre><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>messaging<span class="token punctuation">.</span></span><span class="token class-name">Message</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="8"></td><td><pre><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>stereotype<span class="token punctuation">.</span></span><span class="token class-name">Component</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="9"></td><td><pre></pre></td></tr><tr><td data-num="10"></td><td><pre><span class="token annotation punctuation">@Component</span></pre></td></tr><tr><td data-num="11"></td><td><pre><span class="token annotation punctuation">@EnableBinding</span><span class="token punctuation">(</span><span class="token class-name">Sink</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span> <span class="token comment">// 启动绑定，表示当前类是 sink，负责消费</span></pre></td></tr><tr><td data-num="12"></td><td><pre><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ReceiveMessageListenerController</span> <span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="13"></td><td><pre>    <span class="token annotation punctuation">@Value</span><span class="token punctuation">(</span><span class="token string">"$&#123;server.port&#125;"</span><span class="token punctuation">)</span></pre></td></tr><tr><td data-num="14"></td><td><pre>    <span class="token keyword">private</span> <span class="token class-name">String</span> serverPort<span class="token punctuation">;</span></pre></td></tr><tr><td data-num="15"></td><td><pre></pre></td></tr><tr><td data-num="16"></td><td><pre>    <span class="token annotation punctuation">@StreamListener</span><span class="token punctuation">(</span><span class="token class-name">Sink</span><span class="token punctuation">.</span>INPUT<span class="token punctuation">)</span>  <span class="token comment">//INPUT 在配置文件中配置了</span></pre></td></tr><tr><td data-num="17"></td><td><pre>    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">input</span><span class="token punctuation">(</span><span class="token class-name">Message</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">String</span><span class="token punctuation">></span></span> message<span class="token punctuation">)</span><span class="token punctuation">&#123;</span></pre></td></tr><tr><td data-num="18"></td><td><pre>        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"消费者1号，接受到的消息------->"</span><span class="token operator">+</span>message<span class="token punctuation">.</span><span class="token function">getPayload</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"\t  pory:"</span><span class="token operator">+</span>serverPort<span class="token punctuation">)</span><span class="token punctuation">;</span></pre></td></tr><tr><td data-num="19"></td><td><pre>    <span class="token punctuation">&#125;</span></pre></td></tr><tr><td data-num="20"></td><td><pre><span class="token punctuation">&#125;</span></pre></td></tr></table></figure><h3 id="测试"><a class="markdownIt-Anchor" href="#测试">#</a> 测试</h3>
<p>启动 7001.8801.8802</p>
<p>此时使用生产者生产消息</p>
<p><mark>可以看到，消费者已经接收到消息了</mark></p>
<h1 id="重复消费问题"><a class="markdownIt-Anchor" href="#重复消费问题">#</a> 重复消费问题</h1>
<h2 id="创建消费者2"><a class="markdownIt-Anchor" href="#创建消费者2">#</a> 创建消费者 2</h2>
<p>创建 8803,</p>
<p><mark>与 8802 创建一模一样，就不写了</mark></p>
<p><strong>创建 8803 主要是为了演示重复消费等问题</strong></p>
<p>…</p>
<p>…</p>
<p>…</p>
<p>此时启动 7001.8801.8802.8803</p>
<p>此时生产者生产一条消息</p>
<p>但是此时查询消费者，发现 8802,8803<mark> 都消费到了同一条数据</mark></p>
<h2 id="自定义分组"><a class="markdownIt-Anchor" href="#自定义分组">#</a> 自定义分组</h2>
<p>修改 8802,8803 的配置文件</p>
<figure class="highlight yaml"><figcaption data-lang="YAML"></figcaption><table><tr><td data-num="1"></td><td><pre><span class="token key atrule">bindings</span><span class="token punctuation">:</span> <span class="token comment">#服务的整合处理</span></pre></td></tr><tr><td data-num="2"></td><td><pre>    <span class="token key atrule">input</span><span class="token punctuation">:</span>  <span class="token comment">#这个名字是一个通道的名称</span></pre></td></tr><tr><td data-num="3"></td><td><pre>      <span class="token key atrule">destination</span><span class="token punctuation">:</span> studyExchange  <span class="token comment">#表示要使用的 Exchange 名称定义 指定使用那个 Exchange</span></pre></td></tr><tr><td data-num="4"></td><td><pre>      <span class="token key atrule">content-type</span><span class="token punctuation">:</span> application/json  <span class="token comment">#设置消息类型</span></pre></td></tr><tr><td data-num="5"></td><td><pre>      <span class="token key atrule">binder</span><span class="token punctuation">:</span> defaultRabbit <span class="token comment">#设置要绑定的消息服务的具体设置</span></pre></td></tr><tr><td data-num="6"></td><td><pre>      <span class="token key atrule">group</span><span class="token punctuation">:</span> groupA		<span class="token comment">#配置为一样的就为一个组</span></pre></td></tr></table></figure><p>现在将 8802,8803 都分到了 A 组</p>
<p>然后去重启 02,03</p>
<p>然后此时生产者生产两条消息</p>
<p>在进行测试</p>
<p>可以看到，每人只消费了一条消息，并且没有重复消费</p>
<h1 id="持久化问题"><a class="markdownIt-Anchor" href="#持久化问题">#</a> 持久化问题:</h1>
<p>就是当服务挂了，怎么消费没有消费的数据？？</p>
<p>这里，先将 8802 移除 A 组，</p>
<p>​		然后将 02,03 服务关闭</p>
<p>此时生产者开启，发送 3 条消息</p>
<p>​		此时重启 02,03</p>
<p>​		可以看到，当 02 退出 A 组后，它就获取不到在它宕机的时间段内的数据</p>
<p>​		但是 03 重启后，直接获取到了宕机期间它没有消费的数据，并且消费了</p>
<p>总结:<br>
 也就是，当我们没有配置分组时，会出现消息漏消费的问题</p>
<p>​		而配置分组后，我们可以自动获取未消费的数据</p>

      <div class="tags">
          <a href="/blog/tags/%E5%88%86%E5%B8%83%E5%BC%8F/" rel="tag"><i class="ic i-tag"></i> 分布式</a>
      </div>
  </div>

   <footer>

    <div class="meta">
  <span class="item">
    <span class="icon">
      <i class="ic i-calendar-check"></i>
    </span>
    <span class="text">更新于</span>
    <time title="修改时间：2020-12-24 22:15:51" itemprop="dateModified" datetime="2020-12-24T22:15:51+08:00">2020-12-24</time>
  </span>
  <span id="2020/12/24/Spring Cloud Stream/" class="item leancloud_visitors" data-flag-title="Spring Cloud Stream" title="阅读次数">
      <span class="icon">
        <i class="ic i-eye"></i>
      </span>
      <span class="text">阅读次数</span>
      <span class="leancloud-visitors-count"></span>
      <span class="text">次</span>
  </span>
</div>

      
<div class="reward">
  <button><i class="ic i-heartbeat"></i> 赞赏</button>
  <p>请我喝[茶]~(￣▽￣)~*</p>
  <div id="qr">
      
      <div>
        <img data-src="/blog/images/wechatpay.png" alt="杜朝宇 微信支付">
        <p>微信支付</p>
      </div>
      
      <div>
        <img data-src="/blog/images/alipay.png" alt="杜朝宇 支付宝">
        <p>支付宝</p>
      </div>
      
      <div>
        <img data-src="/blog/images/paypal.png" alt="杜朝宇 贝宝">
        <p>贝宝</p>
      </div>
  </div>
</div>

      

<div id="copyright">
<ul>
  <li class="author">
    <strong>本文作者： </strong>杜朝宇 <i class="ic i-at"><em>@</em></i>凡尘一叶
  </li>
  <li class="link">
    <strong>本文链接：</strong>
    <a href="http://fyduyu.gitee.io/blog/2020/12/24/Spring%20Cloud%20Stream/" title="Spring Cloud Stream">http://fyduyu.gitee.io/blog/2020/12/24/Spring Cloud Stream/</a>
  </li>
  <li class="license">
    <strong>版权声明： </strong>本站所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC9kZWVkLnpo"><i class="ic i-creative-commons"><em>(CC)</em></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

  </footer>

</article>

  </div>
  

<div class="post-nav">
    <div class="item left">
      

  <a href="/blog/2020/12/24/Spring%20Config+Bus/" itemprop="url" rel="prev" data-background-image="https:&#x2F;&#x2F;tva4.sinaimg.cn&#x2F;mw690&#x2F;6833939bly1giclhnx9glj20zk0m8npd.jpg" title="Spring Config+Bus">
  <span class="type">上一篇</span>
  <span class="category"><i class="ic i-flag"></i> SpringCloud</span>
  <h3>Spring Config+Bus</h3>
  </a>

    </div>
    <div class="item right">
      

  <a href="/blog/2020/12/24/Nacos/" itemprop="url" rel="next" data-background-image="https:&#x2F;&#x2F;tva4.sinaimg.cn&#x2F;mw690&#x2F;6833939bly1gicli3sbvtj20zk0m8x6p.jpg" title="Cloud Alibaba Nacos">
  <span class="type">下一篇</span>
  <span class="category"><i class="ic i-flag"></i> Spring Cloud Alibaba</span>
  <h3>Cloud Alibaba Nacos</h3>
  </a>

    </div>
</div>

  
  <div class="wrap" id="comments"></div>


        </div>
        <div id="sidebar">
          

<div class="inner">

  <div class="panels">
    <div class="inner">
      <div class="contents panel pjax" data-title="文章目录">
          <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E7%9A%84%E5%87%A0%E5%A4%A7%E5%BA%94%E7%94%A8%E5%9C%BA%E6%99%AF"><span class="toc-number">1.</span> <span class="toc-text"> 消息中间的几大应用场景</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-spring-cloud-stream-rabbitmq"><span class="toc-number">2.</span> <span class="toc-text"> 使用 Spring Cloud Stream &amp;&amp; RabbitMQ</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%94%9F%E4%BA%A7%E8%80%85"><span class="toc-number">2.1.</span> <span class="toc-text"> 创建生产者</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#pom"><span class="toc-number">2.1.1.</span> <span class="toc-text"> pom</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">2.1.2.</span> <span class="toc-text"> 配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#service%E5%92%8C%E5%AE%9E%E7%8E%B0%E7%B1%BB"><span class="toc-number">2.1.3.</span> <span class="toc-text"> service 和实现类</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#controller"><span class="toc-number">2.1.4.</span> <span class="toc-text"> controller</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%AF%E4%BB%A5%E6%B5%8B%E8%AF%95"><span class="toc-number">2.1.5.</span> <span class="toc-text"> 可以测试</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%B6%88%E8%B4%B9%E8%80%85"><span class="toc-number">2.2.</span> <span class="toc-text"> 创建消费者</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#pom%E6%96%87%E4%BB%B6"><span class="toc-number">2.2.1.</span> <span class="toc-text"> pom 文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6-2"><span class="toc-number">2.2.2.</span> <span class="toc-text"> 配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%9A%E5%8A%A1%E7%B1%BB%E6%B6%88%E8%B4%B9%E6%95%B0%E6%8D%AE"><span class="toc-number">2.2.3.</span> <span class="toc-text"> 业务类 (消费数据)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95"><span class="toc-number">2.2.4.</span> <span class="toc-text"> 测试</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%87%8D%E5%A4%8D%E6%B6%88%E8%B4%B9%E9%97%AE%E9%A2%98"><span class="toc-number">3.</span> <span class="toc-text"> 重复消费问题</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%B6%88%E8%B4%B9%E8%80%852"><span class="toc-number">3.1.</span> <span class="toc-text"> 创建消费者 2</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%86%E7%BB%84"><span class="toc-number">3.2.</span> <span class="toc-text"> 自定义分组</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8C%81%E4%B9%85%E5%8C%96%E9%97%AE%E9%A2%98"><span class="toc-number">4.</span> <span class="toc-text"> 持久化问题:</span></a></li></ol>
      </div>
      <div class="related panel pjax" data-title="系列文章">
        <ul>
          <li><a href="/blog/2020/12/24/Hystrix/" rel="bookmark" title="Hystrix">Hystrix</a></li><li><a href="/blog/2020/12/24/gateway/" rel="bookmark" title="gateway">gateway</a></li><li><a href="/blog/2020/12/24/Spring%20Config+Bus/" rel="bookmark" title="Spring Config+Bus">Spring Config+Bus</a></li><li class="active"><a href="/blog/2020/12/24/Spring%20Cloud%20Stream/" rel="bookmark" title="Spring Cloud Stream">Spring Cloud Stream</a></li><li><a href="/blog/2020/12/24/Spring%20Cloud%20sleuth/" rel="bookmark" title="Spring Cloud sleuth">Spring Cloud sleuth</a></li>
        </ul>
      </div>
      <div class="overview panel" data-title="站点概览">
        <div class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="image" itemprop="image" alt="杜朝宇"
      data-src="/blog/images/touxiang.jpg">
  <p class="name" itemprop="name">杜朝宇</p>
  <div class="description" itemprop="description">个人博客&编程笔记</div>
</div>

<nav class="state">
    <div class="item posts">
      <a href="/blog/archives/">
        <span class="count">8</span>
        <span class="name">文章</span>
      </a>
    </div>
    <div class="item categories">
      <a href="/blog/categories/">
        <span class="count">4</span>
        <span class="name">分类</span>
      </a>
    </div>
    <div class="item tags">
      <a href="/blog/tags/">
        <span class="count">2</span>
        <span class="name">标签</span>
      </a>
    </div>
</nav>

<div class="social">
</div>

<ul class="menu">
  
    
  <li class="item">
    <a href="/blog/" rel="section"><i class="ic i-home"></i>首页</a>
  </li>

    
  <li class="item">
    <a href="/blog/about/" rel="section"><i class="ic i-user"></i>关于</a>
  </li>

        
  <li class="item dropdown">
      <a href="javascript:void(0);"><i class="ic i-feather"></i>文章</a>
    <ul class="submenu">

        
  <li class="item">
    <a href="/blog/archives/" rel="section"><i class="ic i-list-alt"></i>归档</a>
  </li>

        
  <li class="item">
    <a href="/blog/categories/" rel="section"><i class="ic i-th"></i>分类</a>
  </li>

        
  <li class="item">
    <a href="/blog/tags/" rel="section"><i class="ic i-tags"></i>标签</a>
  </li>

  </ul>
        
  <li class="item dropdown">
      <a href="javascript:void(0);"><i class="ic i-magic"></i>链环</a>
    <ul class="submenu">

        
  <li class="item">
    <a href="/blog/friends/" rel="section"><i class="ic i-heart"></i>友链</a>
  </li>

  </ul>

</ul>

      </div>
    </div>
  </div>

  <ul id="quick">
    <li class="prev pjax">
        <a href="/blog/2020/12/24/Spring%20Config+Bus/" rel="prev" title="上一篇"><i class="ic i-chevron-left"></i></a>
    </li>
    <li class="up"><i class="ic i-arrow-up"></i></li>
    <li class="down"><i class="ic i-arrow-down"></i></li>
    <li class="next pjax">
        <a href="/blog/2020/12/24/Nacos/" rel="next" title="下一篇"><i class="ic i-chevron-right"></i></a>
    </li>
    <li class="percent"></li>
  </ul>
</div>


        </div>
        <div class="dimmer"></div>
      </div>
    </main>
    <footer id="footer">
      <div class="inner">
        <div class="widgets">
          
<div class="rpost pjax">
  <h2>随机文章</h2>
  <ul>
      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/Spring-Cloud-Alibaba/" title="分类于 Spring Cloud Alibaba">Spring Cloud Alibaba</a>
</div>

    <span><a href="/blog/2020/12/24/Nacos/" title="Cloud Alibaba Nacos">Cloud Alibaba Nacos</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Spring%20Config+Bus/" title="Spring Config+Bus">Spring Config+Bus</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Hystrix/" title="Hystrix">Hystrix</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/gateway/" title="gateway">gateway</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/java/" title="分类于 java">java</a>
</div>

    <span><a href="/blog/2020/12/23/Druid%E9%85%8D%E7%BD%AE/" title="Druid配置">Druid配置</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Spring%20Cloud%20Stream/" title="Spring Cloud Stream">Spring Cloud Stream</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/SpringCloud/" title="分类于 SpringCloud">SpringCloud</a>
</div>

    <span><a href="/blog/2020/12/24/Spring%20Cloud%20sleuth/" title="Spring Cloud sleuth">Spring Cloud sleuth</a></span>
  </li>

      
  <li class="item">
    
<div class="breadcrumb">
<a href="/blog/categories/%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%E7%AC%94%E8%AE%B0/" title="分类于 开源项目笔记">开源项目笔记</a>
</div>

    <span><a href="/blog/2020/12/23/moti%E5%BC%80%E6%BA%90%E5%AD%A6%E5%88%B0%E7%9A%84/" title="moti">moti</a></span>
  </li>

  </ul>
</div>
<div>
  <h2>最新评论</h2>
  <ul class="leancloud-recent-comment"></ul>
</div>

        </div>
        <div class="status">
  <div class="copyright">
    
    &copy; 2010 – 
    <span itemprop="copyrightYear">2020</span>
    <span class="with-love">
      <i class="ic i-sakura rotate"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">杜朝宇 @ blog</span>
  </div>
  <div class="count">
    <span class="post-meta-item-icon">
      <i class="ic i-chart-area"></i>
    </span>
    <span title="站点总字数">42k 字</span>

    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="ic i-coffee"></i>
    </span>
    <span title="站点阅读时长">38 分钟</span>
  </div>
  <div class="powered-by">
    基于 <span class="exturl" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & Theme.<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FtZWhpbWUvaGV4by10aGVtZS1zaG9rYQ==">Shoka</span>
  </div>
</div>

      </div>
    </footer>
  </div>
<script data-config type="text/javascript">
  var LOCAL = {
    path: '2020/12/24/Spring Cloud Stream/',
    favicon: {
      show: "（●´3｀●）やれやれだぜ",
      hide: "(´Д｀)大変だ！"
    },
    search : {
      placeholder: "文章搜索",
      empty: "关于 「 ${query} 」，什么也没搜到",
      stats: "${time} ms 内找到 ${hits} 条结果"
    },
    valine: true,fancybox: true,copyright: '复制成功，转载请遵守 <i class="ic i-creative-commons"></i>BY-NC-SA 协议。',
    ignores : [
      function(uri) {
        return uri.includes('#');
      },
      function(uri) {
        return new RegExp(LOCAL.path+"$").test(uri);
      }
    ]
  };
</script>

<script src="https://cdn.polyfill.io/v2/polyfill.js"></script>

<script src="//cdn.jsdelivr.net/combine/npm/pace-js@1.0.2/pace.min.js,npm/pjax@0.2.8/pjax.min.js,npm/whatwg-fetch@3.4.0/dist/fetch.umd.min.js,npm/animejs@3.2.0/lib/anime.min.js,npm/algoliasearch@4/dist/algoliasearch-lite.umd.js,npm/instantsearch.js@4/dist/instantsearch.production.min.js,npm/lozad@1/dist/lozad.min.js,npm/quicklink@2/dist/quicklink.umd.js"></script>

<script src="/blog/js/app.js?v=0.2.5"></script>




</body>
</html>
